let oauth_username = document.querySelector("#username")
let oauth_password = document.querySelector("#password")
console.table(oauth_username)
console.table(oauth_password)
let data = browser.storage.local.get(null);
data.then(
    function(result){
        console.log(result);
        document.getElementById("username").value=result.auth.user;
        document.getElementById("password").value=result.auth.password;
        document.getElementById("password_type").value=result.auth.password_type;
        document.getElementById("client_secret").value=result.auth.client_secret;
        document.getElementById("client_id").value=result.auth.client_id;
        // console.log(result)
        if(result.setting.ison)
        {
            document.getElementById("onoff").src="on.png";
        }
        else {
            document.getElementById("onoff").src="off.png";

        }
        // console.log(result)

    }
)
document.getElementById("onoff").onclick = ()=>{
    let onoff;
    
    browser.storage.local.get('setting').then((item)=>{
        onoff = !item.setting.ison
        browser.storage.local.set({setting:{
            ison:onoff
        }})
        if (onoff){
            document.getElementById("onoff").src="on.png";

        }
        else document.getElementById("onoff").src="off.png";
    })
};
document.getElementById("username").onblur = ()=>{
let username = document.getElementById("username").value;
// console.log(username)
browser.storage.local.get().then((item)=>{
    // console.log(item);
    item.auth.user = username;
    browser.storage.local.set(item);
})
}
document.getElementById("password").onblur = ()=>{
let password = document.getElementById("password").value;
browser.storage.local.get().then((item)=>{
    item.auth.password = password;
    browser.storage.local.set(item);
})
// browser.storage.local.set({auth.user:username})
}


document.getElementById("password_type").onblur = ()=>{
let password_type = document.getElementById("password_type").value;
browser.storage.local.get().then((item)=>{
    item.auth.password_type = password_type;
    browser.storage.local.set(item);
})
}

document.getElementById("client_id").onblur = ()=>{
let client_id = document.getElementById("client_id").value;

browser.storage.local.get().then((item)=>{
    item.auth.client_id = client_id;
    browser.storage.local.set(item);
    console.log(item);
})
}



document.getElementById("client_secret").onblur = ()=>{
let client_secret = document.getElementById("client_secret").value;
console.log(client_secret)
browser.storage.local.get().then((item)=>{
    console.log(item);
    item.auth.client_secret = client_secret;
    browser.storage.local.set(item);
})
// browser.storage.local.set({auth.user:username})
}
